#include "ProcessBar.h"
#define NUM 101
#define SPACE ' '
#define STYLE '#'
#define PNUM 6

void ProcessBar(double cur,double total)
{
    char bar[NUM];
    memset(bar,0,sizeof bar);
    char Point[PNUM + 1];
    memset(Point,0,sizeof(Point));
    //一个#对应一个百分比
    int rate = (int)((cur / total) * 100);
    double process = cur / total * 100;
    for(int i = 0;i < rate;i++)
    {
        bar[i] = '#';
    }
    int cnt = rate % PNUM;//小数点的个数
    for(int i = 0;i < PNUM;i++)
    {
        if(i <= cnt)
        Point[i] = '.';
        else
        Point[i] = ' ';//防止stdout的数据一直没有被清掉
    }

    printf("[%-100s][%.2lf%%]%-6s\r",bar,process,Point);
    fflush(stdout);
}
